package com.ruoyi.service.controller;


import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.service.entity.order.PCItemPayVO;
import com.ruoyi.service.entity.order.PCOrderDetailRet;
import com.ruoyi.service.entity.order.PCOrderListRet;
import com.ruoyi.service.entity.order.PCOrderStatusRsp;
import com.ruoyi.service.entity.order.pay.PCOrderPayRet;
import com.ruoyi.service.entity.order.process.PCOrderProcessRet;
import com.ruoyi.service.service.impl.PcOrderService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * PC订单控制
 *
 * @author ZDL
 */

@RestController
@Api(tags = "PC订单账单控制")
@RequestMapping("/PC/orderControl")
public class PcOrderController extends BaseController {

    @Autowired
    private PcOrderService pcOrderService;

    /**
     * 获取订单列表方法
     *
     * @param
     * @return 结果
     */

    @PreAuthorize("@ss.hasPermi('service:orders:list')")
    @GetMapping("/getOrderList")
    public AjaxResult getOrderList(String labelStatus, Integer page, Integer size) {
        try {
            Page<PCOrderListRet> retOrderList = pcOrderService.getOrderList(labelStatus, page, size);
            return AjaxResult.success("获取成功", retOrderList);
        }catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }

    }

    /**
     * 获取订单详情方法
     *
     * @param
     * @return 结果
     */

    @PreAuthorize("@ss.hasPermi('service:orders:list')")
    @GetMapping("/getOrderDetial")
    public AjaxResult getOrderDetial(Long orderId) {
        try {
            PCOrderDetailRet retOrderList = pcOrderService.getOrderDetail(orderId);
            return AjaxResult.success("获取成功", retOrderList);
        }catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }

    }

    /**
     * 订单关闭处理方法
     *
     * @param
     * @return 结果
     */

    @PreAuthorize("@ss.hasPermi('service:orders:list')")
    @PostMapping("/orderStop")
    public AjaxResult orderStop(@RequestBody Map<String, Object> reqBody) {
        try {
            Long orderId = Long.parseLong(reqBody.get("orderId").toString());
            Long reasonId = Long.parseLong(reqBody.get("reasonId").toString());
            String remark = reqBody.get("remark").toString();
            Integer result = pcOrderService.orderStop(orderId, reasonId, remark);
            if (result == 0){
                return AjaxResult.success("订单关闭成功");
            }else {
                return AjaxResult.error("订单关闭失败:状态错误");
            }
        }catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }

    }

    /**
     * 获取订单关闭原因方法
     *
     * @param
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('service:orders:list')")
    @GetMapping("/getStopReason")
    public AjaxResult getStopReason() {
        try {
            List<Map<String, Object>> stopReason = pcOrderService.getStopReason();
            return AjaxResult.success("获取成功", stopReason);
        }catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }

    }

    /**
     * 获取订单跟踪方法
     *
     * @param
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('service:orders:list')")
    @GetMapping("/getOrderTrack")
    public AjaxResult getOrderTrack(Long orderId) {
        try {
            PCOrderProcessRet orderTrack = pcOrderService.getOrderTrack(orderId);
            return AjaxResult.success("获取成功", orderTrack);
        }catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }

    }

    /**
     * 获取账单方法
     *
     * @param
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('service:orders:list')")
    @GetMapping("/getOrderPay")
    public AjaxResult getOrderPay(String labelStatus, Integer page, Integer size) {
        try {
            Page<PCOrderPayRet> PCOrderPay = pcOrderService.getOrderPay(page, size);
            return AjaxResult.success("获取成功", PCOrderPay);
        }catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }

    }

    /**
     * 获取订单筛选中的状态列表
     *
     * @param
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('service:orders:list')")
    @GetMapping("/getAllStatus")
    public AjaxResult getAllStatus() {
        try {

            List<PCOrderStatusRsp> allStatus = pcOrderService.getAllStatus();
            return AjaxResult.success("获取成功", allStatus);

        }catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }

    }

    /**
     * 获取异常订单筛选中的状态列表
     *
     * @param
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('service:orders:list')")
    @GetMapping("/getErrorStatus")
    public AjaxResult getErrorStatus() {
        try {

            List<PCOrderStatusRsp> payStatus = pcOrderService.getErrorStatus();
            return AjaxResult.success("获取成功", payStatus);

        }catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }

    }

    /**
     * 账单状态列表
     *
     * @param
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('service:orders:list')")
    @GetMapping("/getPayStatus")
    public AjaxResult getPayStatus() {
        try {

            List<PCOrderStatusRsp> payStatus = pcOrderService.getPayStatus();
            return AjaxResult.success("获取成功", payStatus);

        }catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }

    }

    /**
     * 账单项目列表
     *
     * @param
     * @return 结果
     */
    @PreAuthorize("@ss.hasPermi('service:orders:list')")
    @GetMapping("/getItemPay")
    public AjaxResult getItemPay() {
        try {

            List<PCItemPayVO> itemPay = pcOrderService.getItemPay();
            return AjaxResult.success("获取成功", itemPay);

        }catch (Exception e){
            return AjaxResult.error(e.getMessage());
        }

    }
    
}
